<template>
	<view class="greyBox padBottom_130">
		<view class="orderTopBlock"
			style="background: url(https://supply.zhongyimotor.com/upload/applet/bg_order_supplier@2x.png) 0 0 no-repeat;background-size: 100%;">
			<view class="title">
				<view class="icon">
					<u-icon name="https://supply.zhongyimotor.com/upload/applet/icon_audit_wait_supplier@2x.png"
						size="32"></u-icon>
				</view>
				{{getStatusLabel(exportType, details.sellerCarOutApply.status)}}
			</view>
			<view class="summary">请耐心等待~</view>
		</view>
		<view class="details">
			<view class="item">
				<view class="top ">
					<view class="title ">出口国家</view>
					<view class="data">{{details.sellerCarOutApply.endHarborCountry}}</view>
				</view>
				<view class="content">
					<view class="dataCell">
						<view class="title">启运港</view>
						<view class="data">{{details.sellerCarOutApply.startHarborName}}</view>
					</view>
					<view class="dataCell">
						<view class="title">目的港</view>
						<view class="data">{{details.sellerCarOutApply.endHarborName}}</view>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="top">
					<view class="title">车辆信息</view>
					<view class="right" @click="carsListPopup = true">更多<u-icon name="arrow-right"></u-icon></view>
				</view>
				<view class="content padRight_0">
					<view class="infoItem export" v-for="(item,index) in details.storeCarLogList" :key="index">
						<view class="infoCell">
							<view class="title">
								<view class="icon">
									<u-icon name="https://supply.zhongyimotor.com/upload/applet/pic_car_supplier@2x.png"
										size="32"></u-icon>
								</view>
								<view class="titleContent">
									{{item.carBrand}}-{{item.carSeries}}-{{item.carModel}}
								</view>
							</view>
							<view class="right" @click="handleFileType(item.carId)">手续<u-icon
									name="arrow-right"></u-icon></view>
						</view>
						<view class="infoCell">
							<view class="title tiny grey padLeft_42 block">
								车架号：{{item.carVin}}
							</view>
						</view>
						<view class="halfBox">
							<view class="tag">
								<view class="icon">
									<u-icon
										name="https://supply.zhongyimotor.com/upload/applet/icon_information_supplier@2x.png"
										size="32"></u-icon>
								</view>
								海运提单
							</view>
							<view class="tag">
								<view class="icon">
									<u-icon
										name="https://supply.zhongyimotor.com/upload/applet/icon_information_supplier@2x.png"
										size="32"></u-icon>
								</view>
								提单
							</view>
							<view class="tag">
								<view class="icon">
									<u-icon
										name="https://supply.zhongyimotor.com/upload/applet/icon_information_supplier@2x.png"
										size="32"></u-icon>
								</view>
								装箱信息
							</view>
						</view>
					</view>
				</view>
				<view class="bottom">
					<view class="totalPrice right">
						<view class="carNum">共计{{totalCarNum}}台</view>
						<view class="price">
							<view class="">合计：</view>
							<view class="priceNum">¥ {{totalPrice}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="item">
				<view class="top ">
					<view class="title ">保证金金额</view>
				</view>
				<view class="content">
					<view class="infoItem export" v-for="(item,index) in carDetails" :key="index">
						<view class="infoCell">
							<view class="title">
								<view class="icon">
									<u-icon name="https://supply.zhongyimotor.com/upload/applet/pic_car_supplier@2x.png"
										size="32"></u-icon>
								</view>
								<view class="titleContent">
									{{item.brand}}-{{item.series}}-{{item.model}}
								</view>
							</view>
							<view class="data grey">x{{item.carNumber}}</view>
						</view>
						<view class="infoCell">
							<view class="title grey">车辆单价</view>
							<view class="data grey">￥{{item.price}}</view>
						</view>
						<view class="infoCell">
							<view class="title grey">保证金比例</view>
							<view class="data grey">{{item.marginRatio}}%</view>
						</view>
						<view class="infoCell">
							<view class="title grey">保证金金额</view>
							<view class="data grey">￥{{item.totalDeposit}}</view>
						</view>
					</view>
					<view class="totalPrice right">
						<view class="carNum">共计{{totalCarNum}}台</view>
						<view class="price">
							<view class="">合计：</view>
							<view class="priceNum">¥ {{totalDeposit}}</view>
						</view>
					</view>
					<!-- 	<view class="dataCell padTop_30" style="border-top: 2rpx solid #F2F2F2;">
						<view class="title">上牌费</view>
						<view class="data fontNum">¥ 10,000.00</view>
						<view class="sub">
							<text>*</text>
							47元/台
						</view>
					</view> -->
					<view class="dataCell" v-for="(item,index) in details.billList" :key="index" v-if="item.type != 10"
						:style='index == 0 ? "border-top: 2rpx solid #F2F2F2;":""'>
						<view class="title">{{getStatusLabel(exportOrderExpenseType, item.type)}}</view>
						<view class="data fontNum">¥ {{item.amount}}</view>
						<!-- <view class="sub" v-if="item.type == 4 || item.type == 5">
							<text>*</text>
							47元/台
						</view> -->
					</view>

				</view>
			</view>
			<view class="item">
				<view class="top ">
					<view class="title ">出口申请单信息</view>
				</view>
				<view class="content">
					<view class="dataCell">
						<view class="title">出口申请单号</view>
						<view class="data">{{details.sellerCarOutApply.id}}</view>
					</view>
					<view class="dataCell">
						<view class="title">申请时间</view>
						<view class="data">{{details.sellerCarOutApply.timeCreate}}</view>
					</view>
				</view>
			</view>
		</view>
		<u-popup v-model="carsListPopup" mode="bottom" :closeable="true">
			<carsInfoList ref="carsInfoList" :list="details.outCarList" :totalPrice="totalPrice"
				:totalCarNum="totalCarNum">
			</carsInfoList>
		</u-popup>
		<u-popup v-model="costListPopup" mode="bottom" :closeable="true">
			<costList ref="costList"></costList>
		</u-popup>
		<u-action-sheet :list="fileTypelist" v-model="fileTypeshow" @click="openCarFile"></u-action-sheet>
		<u-toast ref="uToast" />
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	import {
		exportType,
		getStatusLabel,
		exportOrderExpenseType
	} from '@/utils/status.js';
	import carsInfoList from '@/components/carsInfoList.vue';
	import costList from '@/components/costList.vue';
	import moment from "moment";
	import {
		openFile
	} from '@/utils/index.js';
	export default {
		components: {
			carsInfoList,
			costList
		},
		data() {
			return {
				fileTypelist: [],
				carsListPopup: false,
				costListPopup: false,
				details: {
					sellerCarOutApply: {}
				},
				exportType,
				carDetails: [],
				totalCarNum: 0,
				totalDeposit: 0,
				exportOrderExpenseType,
				totalPrice: 0,
				fileTypeshow: false,
				carFileList: [], //车辆手续，每次调用前清空再赋值

			}
		},
		onLoad(option) {
			this.getExportDetails(option.id)
		},
		onShow() {

		},
		methods: {
			openFile,
			getStatusLabel,
			openCarFile(index) {
				openFile(this.carFileList[index])
			},
			handleFileType(id) {
				let that = this;
				let params = {
					id
				};
				that.carFileList = [];
				that.fileTypelist = [];
				that.$api.getCarFiles(params).then(res => {
					res.result.carFilesList.forEach(item => {
						that.carFileList.push(item.fileUrl)
						switch (item.type) {
							case 1:
								that.fileTypelist.push({
									text: "检测报告"
								});
								item.typeName = "检测报告";
								break;
							case 2:
								that.fileTypelist.push({
									text: "转移待出口手续"
								});
								item.typeName = "转移待出口手续";
								break;
						}
					})
					that.fileTypeshow = true;
				})
			},
			async getExportDetails(id) {
				let that = this;
				let params = {
					id
				};
				await that.$api.getExportDetails(params).then(res => { //出口申请详情
					that.details = res.result;
					that.details.sellerCarOutApply.timeCreate = moment(that.details.sellerCarOutApply
						.timeCreate).format('YYYY-MM-DD HH:mm:ss');
				});
				await that.$api.getExportCarDetails(params).then(res => { //出口申请车辆详情
					that.carDetails = res.result;
					that.carDetails.forEach(item => {
						that.totalCarNum = that.totalCarNum + item.carNumber;
						that.totalDeposit = that.totalDeposit + item.totalDeposit;
						that.totalPrice = that.totalPrice = item.totalPrice;
					})
				});
			},

		}
	};
</script>

<style scoped lang="scss">
	.infoItem {
		&.export {
			background: none;
			padding: 0;
			margin-bottom: 40rpx;

			.infoCell {
				padding-right: 30rpx;
			}

			.halfBox {
				margin-left: 42rpx;
				height: 80rpx;
				line-height: 80rpx;
				background: #F7F7F7;
				border-radius: 16rpx 0rpx 0rpx 16rpx;
				display: flex;

				.icon {
					margin-right: 10rpx;
					margin-top: 5rpx;
				}

				.tag {
					display: flex;
					margin: 0 auto;
				}
			}
		}
	}

	.totalPrice {
		display: flex;
		height: 100rpx;

		line-height: 100rpx;
		background: #FFF;

		&.right {
			justify-content: flex-end;
		}

		.carNum {
			font-size: 24rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #878787;
			margin-right: 20rpx;
		}

		.price {
			font-size: 24rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #202020;
			display: flex;

			.priceNum {
				font-size: 28rpx;
				font-family: DINAlternate, DINAlternate;
				font-weight: bold;
				color: #F76260;
			}
		}
	}
</style>